#include "StringStack.h"


 
 
int DestroyStringStack(StringStack *S){ 				//若栈存在，则销毁它  
	if(S==NULL)
		return -1;
	// for(int i=0;i<MAXSIZE;++i){
	// 	if(S->data[i] !=NULL)
	// 		free(S->data[i]);
	// }
	free(S);
	return 0;
}

int ClearStringStack(StringStack *S){ 				//将栈清空
	if(S==NULL)
		return -1;

	for(int i=0;i<MAXSIZE;++i){
		S->data[i] = 0;
	}
	S->top = -1;							//栈顶指向最后一位，-1表明栈为空
	return 0;
}
bool StringStackEmpty(StringStack S){					//若栈为空，返回true，否则返回false
	if(S.top==-1)
		return true;
	return false;
}

int StringGetTop(StringStack *S,String *e){		//若栈存在且非空，用e返回S的栈顶元素
	if(S->top==-1){
		free(e);
		e = NULL;
		return -1;
	}
	*e = S->data[S->top];
	return 0;
}
int StringStackPush(StringStack *S,String *e){		//若栈S存在，插入新元素e到栈S中并称为栈顶元素  
	if(S==NULL||S->top ==MAXSIZE-1)
		return -1; 
	S->top++;
	S->data[S->top] = *e; 
	return 0;
}

int StringStackPop(StringStack *S,String *e){			//删除栈S中栈顶元素，并用e返回其值 
	if(S==NULL||S->top==-1)
		return -1;
	*e = S->data[S->top];
	S->data[S->top] = 0;
	S->top--; 
	return 0;
}
int StringStackLength(StringStack S){				//返回栈S的元素个数
	return S.top+1;
} 
